use rand::Rng;

fn main() {
    // "if 赋值"
    let age = 5;
    let can_ride = if age >= 12 { true } else { false };
    println!("{age}: {can_ride}");
    let age = 12;
    let can_ride = if age >= 12 { true } else { false };
    println!("{age}: {can_ride}");

    // loop break 赋值
    let mut age = 3;
    age = loop {
        age += 1;
        if age >= 12 {
            break age;
        }
        if age > 10 {
            break age * 2;
        }
    };
    println!("{age}");

    // loop 标签 实现 goto 的效果
    age = 1;
    'l1: loop {
        println!("L1");
        age += 1;
        loop {
            age += rand::thread_rng().gen_range(1..=10); // 随机数包含 10
            println!("L2 {age}");
            if age % 3 == 1 {
                println!("L2-end");
                // continue 'l1;
                break 'l1;
            }
            if age % 5 == 0 {
                break;
            }
        }
        println!("L1-end");
    }
}
